package com.ruoyi.system.facade;

import com.ruoyi.system.domain.BComments;
import com.ruoyi.system.service.impl.BCommentsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class BCommentsFacade {
    @Autowired
    private BCommentsServiceImpl commentsService;
    public List<BComments> getComments(List<BComments> nodes,Long parentId){
        List<BComments> list = new ArrayList<>();
        for (BComments node : nodes) {
            if(parentId.equals(node.getParentId())){
                list.add(node);
                list.addAll(getComments(nodes,node.getId()));
            }
        }
        return list;
    }

    public List<BComments> getChilds(List<BComments> parents){
        List<BComments> list = new ArrayList<>();
        BComments comments=null;
        for (BComments parent : parents) {
            comments = new BComments();
            comments.setParentId(parent.getId());
            List<BComments> bComments = commentsService.selectBCommentsList(comments);
            if(!bComments.isEmpty()){
                list.addAll(bComments);
                list.addAll(getChilds(bComments));
            }
        }
        return list;
    }

    public List<BComments> getChildsExcludeRemark(List<BComments> parents){
        List<BComments> list = new ArrayList<>();
        BComments comments=null;
        for (BComments parent : parents) {
            comments = new BComments();
            comments.setParentId(parent.getId());
            List<BComments> bComments = commentsService.selectBComments(comments);
            if(!bComments.isEmpty()){
                list.addAll(bComments);
                list.addAll(getChilds(bComments));
            }
        }
        return list;
    }
}
